//
//  UIViewExtension.swift
//  PropertyCommunity
//
//  Created by benwang on 2021/6/24.
//

import UIKit

extension UIView {

  static var className: String {
    return NSStringFromClass(Self.self)
  }

  static var nib: UINib {
    return UINib(nibName: className, bundle: Bundle.main)
  }

  static var loadFromNib: Self {
    return nib.instantiate(withOwner: nil, options: nil).first as! Self
  }
}

public extension UIView {

  var top: CGFloat {
    get {
      self.frame.origin.y
    }
    set {
      self.frame.origin.y = newValue
    }
  }

  var left: CGFloat {
    get {
      self.frame.origin.x
    }
    set {
      self.frame.origin.x = newValue
    }
  }

  var bottom: CGFloat {
    get {
      self.top + self.frame.size.height
    }
    set {
      self.frame.origin.y = newValue - self.frame.size.height
    }
  }
}


public extension UIView {

  @IBInspectable var cornerRadius: CGFloat {
    get {
      return layer.cornerRadius
    }
    set {
      layer.cornerRadius = newValue
    }
  }

  @IBInspectable var borderWidth: CGFloat {
    get {
      return layer.borderWidth
    }
    set {
      layer.borderWidth = newValue
    }
  }

  @IBInspectable var borderColor: UIColor {
    get {
      return UIColor(cgColor: layer.borderColor!)
    }
    set {
      layer.borderColor = newValue.cgColor
    }
  }

}
